package com.wx_shop.api.util.wx.util;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataExpiresIn<T> implements Serializable {
	static Logger logger = LoggerFactory.getLogger(DataExpiresIn.class);
	private static final long serialVersionUID = 1L;
	private T value;
	private long expires_in; // 有效期秒
	private long now_time; // 存储时的时间秒
	
	public DataExpiresIn() {}
	
	public DataExpiresIn(T value, long expires_in) {
		this.value = value;
		this.expires_in = expires_in;
		now_time = System.currentTimeMillis() / 1000;
	}
	
	public T getValue() {
		long nn = System.currentTimeMillis() / 1000;
		if(nn - now_time < expires_in) {
			logger.debug("get cache data {}", value);
			return value;
		}
		return null;
	}
}
